<template>
  <div v-if="blogList == 0" class="active blog_list">
    <img src="https://mp-blog.csdn.net/mp_blog/img/monkey-blank.137fa3ce.png" class="monkey_lank">
    <div class="blank_tips">回收站空空如也</div>
  </div>
  <div v-else v-loading="loading">
    <div class="describe" v-for="item in blogList">
      <div class="content-box">
        <div class="title-list"><h4>{{item.title}}</h4></div>
        <div class="content-list">{{item.content}}</div>
        <div class="footer-list" style="float: right">
          <el-button size="mini" type="text" @click="recovery(item.id)" style="margin-right: 10px">
            还原
          </el-button>
          <el-button size="mini" type="text" @click="completely(item.id)" style="margin-right: 15px; color: red">
            彻底删除
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {deleteBlogList,completelyDelete,recoveryBlog} from "@/api/blog";
  export default {
    data() {
      return {
        blogList: [],
        loading: true,
      }
    },
    created() {
      this.deleteBlogList()
    },
    methods: {
      // 查看逻辑删除的博客
      deleteBlogList() {
        this.loading = true
        deleteBlogList().then(res =>{
          this.blogList = res.data.data
          this.loading = false
        })
      },
      // 彻底删除博客
      completely(id){
        this.$confirm('是否确认彻底删除该博客?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          completelyDelete(id)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.deleteBlogList()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      // 还原
      recovery(id){
        this.$confirm('是否确认还原该博客?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          recoveryBlog(id)
          this.$message({
            type: 'success',
            message: '还原成功!'
          })
          this.deleteBlogList()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消还原'
          })
        })
      }
    },
  }
</script>

<style scoped>
  .describe {
    background-color: white;
    width: 100%;
    height: 154px;
    margin-top: 10px;
    border-radius: 10px;
  }
  .describe:hover {
    box-shadow: 0 1px 6px rgba(0,0,0,.2);
    border-color: #eee;
  }
  .content-box {
    padding-top: 10px;
    width: 96%;
    height: 132px;
    padding-left: 2%;
  }
  h4 {
    margin-top: 0px;
    margin-bottom: 0px;
  }
  .title-list {
    width: 100%;
    font-size: 18px;
    font-weight: 500;
    line-height: 24px;
    color: #222226;
    cursor: pointer;
  }
  .content-list {
    margin-top: 16px;
    width: 100%;
    height: 65px;
    line-height: 22px;
    text-align: left;
    white-space: normal;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:3;
  }
  .footer-list {
    width: 100%;
    text-align: right;
    margin-top: 10px;
    font-weight: 500;
  }
  .blog_list.active {
    padding: 95px;
  }
  .blog_list {
    text-align: center;
  }
  .blog_list .monkey_lank {
    display: block;
    width: 200px;
    height: 200px;
    margin: auto;
    border-style: none;
  }
  .blog_list div.blank_tips {
    margin-bottom: 4px;
    font-size: 16px;
    color: #999aaa;
    letter-spacing: 2px;
    text-align: center;
  }
</style>
